//这里可以导入其他文件（比如：组件，工具js，第三方插件js，json文件，图片文件等等）
//例如：import 《组件名称》 from '《组件路径》';
import { Image as VanImage } from "vant";
import { scrollMixin } from "utils/mixin";
export default {
  mixins: [scrollMixin], //加载更多
  name:'',
  //import引入的组件需要注入到对象中才能使用
  components: {
    VanImage
  },
  data() {
    return {
      active:0,
      levelId:'',
      managerName:'',
      isLoadMore: true,
      page: 1,
      totalPage: 0,
      gradeArr:[],
      directlyList:[
      ]
    };
  },
  //监听属性 类似于data概念
  computed: {},
  //监控data中的数据变化
  watch: {},
  //方法集合
  methods: {
    directlyOn(index) {
      this.directlyList[index].checked = !this.directlyList[index].checked;
    },
    directlyTab(id) {
      console.log(id);
      this.levelId = Number(id);
      this.page = 1;
      this.teamIndex();
    },
    teamIndex() {
      let json = {
        basic_info:1,
        level_id:this.levelId,
        page:this.page
      };
      $http.post("plugin.manager-team.frontend.modules.manager.controllers.records.index", json, "正在获取").then(
        response => {
          if (response.result == 1) {
            let res = response.data;
            let basic_info = response.basic_info;
            this.gradeArr = res.level_list;
            this.directlyList = res.page_list.data;
            this.isLoadMore = true;
            this.totalPage = res.page_list.last_page;
            if (!this.totalPage) {
              this.page = 0;
            }
            this.managerName = res.manager_name;
            this.directlyList.forEach((item,index) => {
              this.$set(item, 'checked', false);
            })
            console.log(res);
          } else {
            this.page = this.page - 1;
            this.isLoadMore = false;
            this.$dialog.alert({ message: response.msg });
          }
        },
        function(response) {
          // console.log(response);
          // error callback
        }
      );
    },
    initData(){
      this.page = 1;
      this.level_id = '';
      this.isLoadMore = true;
    },
    //获取更多数据
    getMoreData() {
      this.isLoadMore = false; // 防止多次请求分页数据
      if (this.page >= this.totalPage) {
        return;
      } else {
        this.page = this.page + 1;
        let json = {
          page:this.page,
          level_id:this.levelId
        };
        $http.post("plugin.manager-team.frontend.modules.manager.controllers.records.index", json, "加载中").then(
          res => {
            this.isLoadMore = true;

            if (res.result === 1) {
              let myData = res.data.page_list.data;
              console.log(myData);
              myData.forEach((item,index) => {
                this.$set(item, 'checked', false);
              })
              this.directlyList = [...this.directlyList, ...myData]; //数组拼接
            } else {
              this.query.page = this.query.page - 1;
              this.isLoadMore = false;
            }
          },
          function(response) {
            // error callback
          }
        );
      }
    },
  },
  //生命周期 - 创建完成（可以访问当前this实例）
  created() {
  
  },
  //生命周期 - 挂载完成（可以访问DOM元素）
  mounted() {
  
  },
  beforeCreate() {}, //生命周期 - 创建之前
  beforeMount() {}, //生命周期 - 挂载之前
  beforeUpdate() {}, //生命周期 - 更新之前
  updated() {}, //生命周期 - 更新之后
  beforeDestroy() {}, //生命周期 - 销毁之前
  destroyed() {}, //生命周期 - 销毁完成
  activated() {
    this.initData();
    this.teamIndex();
  }, //如果页面有keep-alive缓存功能，这个函数会触发
}